<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>dom联系</title>
</head>

<body>

    你喜欢的运动：
    <input type="checkbox" name="篮球" id="basketball">篮球</input>
    <input type="checkbox" id="football">足球</input>

    <input type="checkbox" id="tableball">台球</input>
    <input  type="checkbox" id="allEach">全选/全不选</button>

    <button id="all">全选</button>
    <button id="noall">全不选</button>
    <button id="noequal">反选</button>




</body>

<script>
    window.onload = function () {
        document.getElementById("all").onclick = function () {
            var flag = true;
            let collections = document.getElementsByTagName("input")
            let basket = document.getElementById("basketball")

            for (var i = 0; i < collections.length; i++) {
                collections[i].checked = true
            }


        };

        document.getElementById("noall").onclick = function () {
            var flag = true;
            let collections = document.getElementsByTagName("input")
            let basket = document.getElementById("basketball")

            for (var i = 0; i < collections.length; i++) {
                collections[i].checked = false
            }
        };


        document.getElementById("noequal").onclick = function () {

            let collections = document.getElementsByTagName("input")
            let basket = document.getElementById("basketball")

            for (var i = 0; i < collections.length; i++) {
                collections[i].checked = !collections[i].checked
            }
        }

       var ae= document.getElementById("allEach").onclick=function(){
        //    this.checked=!this.checked
            let collections = document.getElementsByTagName("input")
                for (var i = 0; i < collections.length; i++) {
                collections[i].checked =this.checked
            }
          
        }


    }
</script>

</html>